$(function(){
    //轮播
    $('.pagination-box').on('click','.pagination-unit',function(){
        $(this).addClass('pagination-unit-active').siblings('.pagination-unit').removeClass('pagination-unit-active')
        var m =$(this).index()/4*100 + '%';
        $('.slider-container').css({
            transform:'translateX(-'+m +')'
        })
    })

//    律师提现申请开始



    //弹框开始
    $('#handled').on('click',choose);
    $('#refuse').on('click',choose);

    $('#lawyer_sequence').on('click',function(){
        if ( $(this).hasClass('isup')){

            $(this).removeClass('isup').addClass('isdown');

            orderBy=0;

            lawyerTx_list();

        }else if($(this).hasClass('isdown')){
            $(this).removeClass('isdown').addClass('isup');

            orderBy=1;

            lawyerTx_list();

        }else{
            $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');
            $(this).addClass('isup');
        }

    })



    $('#pay_sequence').on('click',function(){
        if ( $(this).hasClass('isup')){

            $(this).removeClass('isup').addClass('isdown');

            orderBy2=0;

            payflowno_list();

        }else if($(this).hasClass('isdown')){

            $(this).removeClass('isdown').addClass('isup');

            orderBy2=1;

            payflowno_list();

        }else{

            $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');

            $(this).addClass('isup');

            orderBy2=1;

            payflowno_list();
        }

    })




    $('#pay_sequence2').on('click',function(){
        if ( $(this).hasClass('isup')){

            $(this).removeClass('isup').addClass('isdown');

            orderBy2=2;

            payflowno_list();

        }else if($(this).hasClass('isdown')){
            $(this).removeClass('isdown').addClass('isup');
            alert("下");
            orderBy2=3;

            payflowno_list();

        }else{

            $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');
            $(this).addClass('isup');

            orderBy2=3;

            payflowno_list();
        }

    })


    $('#pay_sequence3').on('click',function(){
        if ( $(this).hasClass('isup')){

            $(this).removeClass('isup').addClass('isdown');

            orderBy2=4;

            payflowno_list();

        }else if($(this).hasClass('isdown')){
            $(this).removeClass('isdown').addClass('isup');

            orderBy2=5;

            payflowno_list();

        }else{
            $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');
            $(this).addClass('isup');

            orderBy2=5;

            payflowno_list();
        }

    })

    function choose(){

       if( $('#handled').prop('checked')){
           $('.odd-numbers-box').css({
               'display':'inline-block'
           });
       }else {
           $('.odd-numbers-box').css({
               'display':'none'
           });
       }
    }

    $('.handle-confirm').on('click',function(){

        handle_lawyertx();


    })
    $('.handle-cancel').on('click',function(){
        $('#handle-pop').hide();
    })
//    弹框结束
    $('#lawyer-check-all').on('click',function(){
        $('.lawyer-check-unit').prop('checked',$(this).prop('checked'))
    })

//    律师提现申请结束
//    客户充值记录开始
    //充值时间
    $('#top-up-start').on('focus',function(){
        WdatePicker({
            //minDate:'%y-%M-{%d+1}' ,
            maxDate:'#F{$dp.$D(\'top-up-end\',{d:0});}',
            onpicked:function(){
                console.log($(this).val());
            }
        })
    })
    $('#top-up-end').on('focus',function(){
        WdatePicker({
            minDate:'#F{$dp.$D(\'top-up-start\',{d:0});}',
            onpicked:function(){
                console.log($(this).val());
            }

        })
    })

    $('#client-check-all').on('click',function(){
        $('.client-check-unit').prop('checked',$(this).prop('checked'))
    })


    //查询律师提现
    lawyerTx_list();


    //查询用户的充值记录
    payflowno_list();

})



/**
 *加载律师提现记录
 */
var pageNum=1;

/**
 * 全部变量，提现记录的id
 */
var static_tx_id;

/**
 * 排序参数
 */
var orderBy=0;

function  lawyerTx_list(){

    Loading.show();

    var searchLawyerTx = $("#search_lawyer_tx").serialize();

    $.ajax({
        type:"get",
        url:"/finance/getLawyertxList",
        data:searchLawyerTx+"&pageNum="+pageNum+"&orderBy="+orderBy,
        dataType: "json",
        success:function(data){

            v_data(function(){return bt('lawyertxlist_tmpl', data.data);},lawyerTx_list,data.data.result.length,data.data.total,'lawyertxlist');

        },
        error:function(){
            alert("报错啦");
        }
    })

    $("#lawyer-check-all").removeAttr("checked");


}

/*
*搜索律师提现列表
 */
function search_lawyertx(){

    pageNum=1;

    lawyerTx_list();

}


/*
*打开处理页面
 */
function open_handle_page(tx_id){
    static_tx_id=tx_id;
    $('#handle-pop').show();
}


/**
 *  处理方法
 **/

function handle_lawyertx(){


    if(!$("#edit_handle").validate().form()){

        return;

    }

    var edit_handle = $("#edit_handle").serialize();

    Loading.show();

    $.ajax({
        type:"get",
        url:"/finance/updateLawyerTxHandle",
        data:edit_handle+"&txId="+static_tx_id,
        dataType: "json",
        success:function(data){

            if(data.code=="1"){

                alert(data.msg);

                $('#handle-pop').hide();

                lawyerTx_list();

            }else{

                alert(data.msg);

            }


            Loading.hide();

        },
        error:function(){
            alert("报错啦");
        }
    })


}









/**
 *加载用户充值记录
 */
var pageNum2=1;

/**
 * 全部变量的排序
 */

var orderBy2=0;


function  payflowno_list(){


    Loading.show();

    var searchPayFlowno = $("#search_pay_flowno").serialize();

    $.ajax({
        type:"get",
        url:"/finance/getPayFlownoList",
        data:searchPayFlowno+"&pageNum="+pageNum2+"&orderBy="+orderBy2,
        dataType: "json",
        success:function(data){

            console.log(JSON.stringify(data));

            v_data2(function(){return bt('payflownolist_tmpl', data.data);},payflowno_list,data.data.result.length,data.data.total,'payflownolist');


            $.ajax(
                {
                    type:"get",
                    url:"/finance/gettotalmoney",
                    data:searchPayFlowno,
                    dataType:"json",
                    success:function(data){
                      $("#totalmoney").html("支付宝已支付总金额："+ back_money_handler(data.total_alibabaprice /100 )+"#微信已支付总金额："+back_money_handler(data.total_wxprice/100));
                    }
                }
            );

        },
        error:function(){
            alert("报错啦");
        }
    })


    $("#client-check-all").removeAttr("checked");






}

/*
 *搜索用户充值列表
 */
function search_payflowno(){

    pageNum2=1;

    payflowno_list();

}

/**
 * 导出excel
 * @param id
 * @param name
 */
function exportEXCEL(id,name){


    $("#"+id).table2excel({
        // exclude CSS class
        exclude: ".noExl",
        name:name,
        exclude_img:true,
        filename: name //do not include extension
    });
   // $('#lawyer_tx_table').tableExport({ type: 'excel', separator: ';', escape: 'false' });

}


/**
 * 导出excel律师提现记录
 */
function excel_lawyertx(){



    var searchLawyerTx = $("#search_lawyer_tx").serialize();

    window.open("/finance/excelLaywerWithList?"+searchLawyerTx+"&orderBy="+orderBy);


}


/**
 * 导出excel用户充值记录
 */
function excel_payflowno(){

    var searchPayFlowno = $("#search_pay_flowno").serialize();

    window.open("/finance/excelPayList?"+searchPayFlowno+"&orderBy="+orderBy2);
}